using System;
using System.Collections;
using System.DirectoryServices;

namespace BEGDC.CC.Entity
{
	#region OperationLog

	/// <summary>
	/// OperationLog object for NHibernate mapped table 'OperationLog'.
	/// </summary>
	[Serializable]
	public class OperationLog : System.IComparable
		{
		#region Member Variables
		
		protected int _id;
		protected Nullables.NullableDateTime _time;
		protected string _module;
		protected string _description;
		protected string _appNO;
		protected string _currentStep;
		protected string _operationType;
		protected Employee _employee;
		protected static String _sortExpression = "Id";
		protected static SortDirection _sortDirection = SortDirection.Ascending;

		#endregion

		#region Constructors

		public OperationLog() { }

		public OperationLog( Nullables.NullableDateTime time, string module, string description, string appNO, string currentStep, string operationType, Employee employee )
		{
			this._time = time;
			this._module = module;
			this._description = description;
			this._appNO = appNO;
			this._currentStep = currentStep;
			this._operationType = operationType;
			this._employee = employee;
		}

		#endregion

		#region Public Properties

		public int Id
		{
			get {return _id;}
			set {_id = value;}
		}

		public Nullables.NullableDateTime Time
		{
			get { return _time; }
			set { _time = value; }
		}

		public string Module
		{
			get { return _module; }
			set
			{
				if ( value != null && value.Length > 50)
					throw new ArgumentOutOfRangeException("Invalid value for Module", value, value.ToString());
				_module = value;
			}
		}

		public string Description
		{
			get { return _description; }
			set
			{
				if ( value != null && value.Length > 4000)
					throw new ArgumentOutOfRangeException("Invalid value for Description", value, value.ToString());
				_description = value;
			}
		}

		public string AppNO
		{
			get { return _appNO; }
			set
			{
				if ( value != null && value.Length > 50)
					throw new ArgumentOutOfRangeException("Invalid value for AppNO", value, value.ToString());
				_appNO = value;
			}
		}

		public string CurrentStep
		{
			get { return _currentStep; }
			set
			{
				if ( value != null && value.Length > 50)
					throw new ArgumentOutOfRangeException("Invalid value for CurrentStep", value, value.ToString());
				_currentStep = value;
			}
		}

		public string OperationType
		{
			get { return _operationType; }
			set
			{
				if ( value != null && value.Length > 50)
					throw new ArgumentOutOfRangeException("Invalid value for OperationType", value, value.ToString());
				_operationType = value;
			}
		}

		public Employee Employee
		{
			get { return _employee; }
			set { _employee = value; }
		}

        public static String SortExpression
        {
            get { return _sortExpression; }
            set { _sortExpression = value; }
        }

        public static SortDirection SortDirection
        {
            get { return _sortDirection; }
            set { _sortDirection = value; }
        }
		#endregion
		
        #region IComparable Methods
        public int CompareTo(object obj)
        {
			if (!(obj is OperationLog))
				throw new InvalidCastException("This object is not of type OperationLog");
			
			int relativeValue;
			switch (SortExpression)
			{
				case "Id":
					relativeValue = this.Id.CompareTo(((OperationLog)obj).Id);
					break;
				case "Time":
					relativeValue = this.Time.CompareTo(((OperationLog)obj).Time);
					break;
				case "Module":
						relativeValue = ( this.Module != null ) ? this.Module.CompareTo(((OperationLog)obj).Module) : -1;
					break;
				case "Description":
						relativeValue = ( this.Description != null ) ? this.Description.CompareTo(((OperationLog)obj).Description) : -1;
					break;
				case "AppNO":
						relativeValue = ( this.AppNO != null ) ? this.AppNO.CompareTo(((OperationLog)obj).AppNO) : -1;
					break;
				case "CurrentStep":
						relativeValue = ( this.CurrentStep != null ) ? this.CurrentStep.CompareTo(((OperationLog)obj).CurrentStep) : -1;
					break;
				case "OperationType":
						relativeValue = ( this.OperationType != null ) ? this.OperationType.CompareTo(((OperationLog)obj).OperationType) : -1;
					break;
                default:
                    goto case "Id";
			}
            if (OperationLog.SortDirection == SortDirection.Ascending)
				relativeValue *= -1;
			return relativeValue;
		}
		#endregion
	}

	#endregion
}
